{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import connections,Collection\n",
    "connections.connect(\n",
    "  alias=\"default\", \n",
    "  host='localhost', \n",
    "  port='19530'\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好！有什么我可以帮助你的吗？'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import openai\n",
    "openai.api_type = \"azure\"\n",
    "openai.api_base = \"https://us1.openai.azure.com/\"\n",
    "openai.api_version = \"2023-03-15-preview\"\n",
    "openai.api_key = \"64aae82617224549ab00d48e6d80e662\"\n",
    "\n",
    "response = openai.ChatCompletion.create(\n",
    "  engine=\"GPT35\",\n",
    "  messages = [{\"role\":\"user\",\"content\":\"你好\"}],\n",
    "  temperature=0.7,\n",
    "  max_tokens=800,\n",
    "  top_p=0.95,\n",
    "  frequency_penalty=0,\n",
    "  presence_penalty=0,\n",
    "  stop=None)\n",
    "response['choices'][0]['message']['content']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import CollectionSchema, FieldSchema, DataType\n",
    "paragraph_id = FieldSchema(\n",
    "  name=\"paragraph_id\", \n",
    "  dtype=DataType.INT64, \n",
    "  is_primary=True\n",
    ")\n",
    "\n",
    "article_id = FieldSchema(\n",
    "  name=\"article_id\", \n",
    "  dtype=DataType.INT64\n",
    ")\n",
    "user_id = FieldSchema(\n",
    "  name=\"user_id\", \n",
    "  dtype=DataType.INT64\n",
    ")\n",
    "word_count = FieldSchema(\n",
    "  name=\"word_count\", \n",
    "  dtype=DataType.INT64\n",
    ")\n",
    "paragraph_vector = FieldSchema(\n",
    "  name=\"paragraph_vector\", \n",
    "  dtype=DataType.FLOAT_VECTOR, \n",
    "  dim=768\n",
    ")\n",
    "schema = CollectionSchema(\n",
    "  fields=[paragraph_id,article_id, word_count,paragraph_vector, user_id], \n",
    "  description=\"Paragraph search\"\n",
    ")\n",
    "collection_name = \"article_paragraph_use_mpnet\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# from pymilvus import Collection\n",
    "\n",
    "# # 连接到Milvus服务器，假设已经建立了连接\n",
    "# # connections.connect(alias='default', host='your_host', port='your_port')\n",
    "\n",
    "# # 指定想要删除的集合名称\n",
    "# collection_name = '2'\n",
    "\n",
    "# # 获取集合对象\n",
    "# collection = Collection(name=collection_name)\n",
    "\n",
    "# # 删除集合\n",
    "# collection.drop()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "collection = Collection(\n",
    "    name=collection_name, \n",
    "    schema=schema, \n",
    "    using='default', \n",
    "    shards_num=8,\n",
    "    consistency_level=\"Strong\"\n",
    "    )\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 生成向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sentence_transformers import SentenceTransformer\n",
    "model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentences = \"This is an example sentence\"\n",
    "embeddings = model.encode(sentences)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sentences = \"This is an example sentence\"\n",
    "\n",
    "# model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')\n",
    "# embeddings = model.encode(sentences)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.18845685,  0.17425628,  0.0544778 ,  0.2905176 ,  0.16766429,\n",
       "       -0.04720669,  0.6455801 ,  0.15980898,  0.22689259, -0.03089055,\n",
       "        0.25588343, -0.05258765, -0.22610147, -0.05710629,  0.13042627,\n",
       "        0.1249535 ,  0.31749612,  0.1944439 , -0.58632535, -0.01258586,\n",
       "        0.6099092 ,  0.16432752,  0.03331136, -0.2738308 , -0.28975758,\n",
       "       -0.21119726, -0.02261387, -0.17035918,  0.16159   ,  0.06082746,\n",
       "       -0.2416241 ,  0.18579197,  0.42740965,  0.19295172, -0.0723446 ,\n",
       "        0.16611089,  0.10442813,  0.20477226,  0.21116722,  0.19973989,\n",
       "       -0.09408254, -0.17383662,  0.06427367,  0.2802548 , -0.2953059 ,\n",
       "        0.06209544,  0.10427698, -0.0236441 ,  0.12913162, -0.1261745 ,\n",
       "       -0.17898989,  0.03700584, -0.61250603,  0.05029819,  0.17730354,\n",
       "        0.22494118,  0.17386067, -0.03840288, -0.21286802,  0.25849256,\n",
       "       -0.12101638,  0.30971512, -0.41966373,  0.00907657,  0.14188913,\n",
       "       -0.30556947,  0.17621148, -0.07087358, -0.6203314 ,  0.6770835 ,\n",
       "        0.01723747,  0.18405135, -0.16785757,  0.2045265 , -0.14770274,\n",
       "       -0.06175369,  0.63017434,  0.11120194,  0.05153067,  0.15927422,\n",
       "       -0.05370879,  0.05350968,  0.14135505,  0.11239245, -0.48411804,\n",
       "       -0.1699363 , -0.053218  ,  0.27650324,  0.11777706, -0.3491252 ,\n",
       "       -0.5137555 , -0.32844043,  0.54240465, -0.05326692,  0.22918324,\n",
       "       -0.01275977,  0.10331817, -0.3362778 ,  0.24764968,  0.8155241 ,\n",
       "       -0.08930925,  0.24757884, -0.12043518,  0.01898997,  0.32457107,\n",
       "       -0.26162428, -0.19714794,  0.0144098 , -0.03558915, -0.3274298 ,\n",
       "       -0.04829862,  0.18030523,  0.02312147, -0.14245273, -0.19523908,\n",
       "       -0.55491173,  0.04145997, -0.08038603, -0.12909943,  0.3454115 ,\n",
       "        0.04179802, -0.17788361,  0.3445857 ,  0.10763668,  0.00641303,\n",
       "       -0.8081875 ,  0.18311797, -0.06116292,  0.10278971, -0.35960668,\n",
       "       -0.12100703, -0.3190548 ,  0.14434478,  0.19774653, -0.04758287,\n",
       "       -0.13626674,  0.27915877,  0.10766114, -0.03404974,  0.06557186,\n",
       "        0.03390291,  0.47428307,  0.03201592,  0.43823132, -0.18881238,\n",
       "        0.3911015 , -0.29364923, -0.09019411, -0.08186891,  0.15285055,\n",
       "        0.1180672 , -0.29786888,  0.18289225, -0.23518266, -0.04338415,\n",
       "       -0.08308796, -0.01447851,  0.0893662 ,  0.11753733, -0.06312162,\n",
       "       -0.13069399,  0.16051391, -0.07993034,  0.04523432, -0.1163742 ,\n",
       "       -0.19606258,  0.03943979, -0.34911758, -0.01147568,  0.26085487,\n",
       "        0.3166197 , -0.08063637, -0.18066706,  0.02020079, -0.08835147,\n",
       "       -0.0167806 , -0.38134593,  0.15447454, -0.03228499,  0.01385774,\n",
       "        0.31472564, -0.2918775 , -0.11789735, -0.02333087, -0.22907731,\n",
       "        0.24850817, -0.08262312,  0.17519872,  0.07053146,  0.17890434,\n",
       "       -0.19748053,  0.11594964,  0.22957717,  0.08844835, -0.3413851 ,\n",
       "       -0.00305377,  0.44035333,  0.2076507 , -0.23839878,  0.1454994 ,\n",
       "       -0.32511157, -0.04974953,  0.08412308, -0.2610328 ,  0.42206797,\n",
       "       -0.27341738,  0.22958672, -0.18960787, -0.17343768, -0.04636088,\n",
       "        0.12553112,  0.47853264, -0.5529563 ,  0.21560642,  0.069723  ,\n",
       "        0.07278681, -0.23890154,  0.19889092, -0.42354292, -0.16452737,\n",
       "       -0.22758181, -0.04920295,  0.23738672, -0.45531532, -0.06247041,\n",
       "        0.5811021 , -0.08885654, -0.05396921,  0.28655335, -0.48124054,\n",
       "       -0.06124162, -0.28116307,  0.36897892, -0.2953122 , -0.71865666,\n",
       "       -0.38774464, -0.16324662,  0.13904096, -0.02087949, -0.05228818,\n",
       "       -0.10613599, -0.05529162, -0.06380261,  0.02985431,  0.01341964,\n",
       "        0.01263404,  0.11067462, -0.07000595, -0.01710501,  0.10809223,\n",
       "       -0.11134936, -0.4287482 , -0.33341143,  0.14569518, -0.2426156 ,\n",
       "        0.15181318, -0.08179675,  0.2433622 , -0.37745434,  0.08149586,\n",
       "        0.09220809, -0.2765346 ,  0.04063625,  0.20002249, -0.04784403,\n",
       "       -0.40510842,  0.18088534,  0.08081246,  0.02778465,  0.14977627,\n",
       "       -0.45252854, -0.06112511,  0.22713478, -0.13096146, -0.29849124,\n",
       "       -0.15302691, -0.26123852, -0.22188595,  0.04267641, -0.20062755,\n",
       "       -0.02200285, -0.4943687 ,  0.53533345, -0.02982718, -0.01962636,\n",
       "        0.057063  ,  0.1786913 ,  0.31158486,  0.36374244,  0.21134542,\n",
       "       -0.3937495 ,  0.17488788,  0.01140852, -0.10499526, -0.143838  ,\n",
       "       -0.10661037, -0.4385612 ,  0.04653321, -0.26895493, -0.03211478,\n",
       "        0.31267306, -0.28747162, -0.30524963, -0.02647258,  0.25250226,\n",
       "       -0.18864211,  0.2102422 ,  0.07654761, -0.3165552 ,  0.13155591,\n",
       "       -0.02851393,  0.266221  , -0.4398153 ,  0.33574796, -0.02058759,\n",
       "       -0.2281362 , -0.18404235,  0.15129349, -0.20930652, -0.45565373,\n",
       "        0.0973675 , -0.1739389 , -0.12940052, -0.11562896,  0.27910313,\n",
       "       -0.15251721,  0.16353638, -0.18450584, -0.00569296, -0.3015109 ,\n",
       "       -0.10034243,  0.33604607, -0.01101627,  0.01471755, -0.07627992,\n",
       "        0.78714746, -0.28120586, -0.23819914,  0.10064668,  0.5990075 ,\n",
       "        0.50067776,  0.1581891 , -0.2903747 ,  0.06542068, -0.14885986,\n",
       "        0.06843901, -0.03958019,  0.14649287, -0.14633441,  0.1791303 ,\n",
       "        0.2805238 ,  0.3625296 , -0.3133771 , -0.04091792, -0.07653181,\n",
       "        0.15323578,  0.19257912, -0.3736528 ,  0.09541661, -0.28398472,\n",
       "       -0.00148429, -0.04926235,  0.4472231 ,  0.657747  ,  0.16523838,\n",
       "        0.05867776, -0.40437815, -0.0780133 , -0.25537845, -0.36102334,\n",
       "       -0.09678138, -0.14205818,  0.14746185,  0.09517751,  0.05682939,\n",
       "       -0.17478277,  0.261479  ,  0.14114727,  0.12460954,  0.08857516,\n",
       "        0.1845388 ,  0.27090225,  0.34769496,  0.08729663], dtype=float32)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "embeddings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "生成的UUID： 4f097d7d-dcb0-4a89-ab66-d3e3381ded9f\n",
      "转换为int型： 105058287611755763249525277135631936927\n"
     ]
    }
   ],
   "source": [
    "import uuid\n",
    "\n",
    "# 生成UUID\n",
    "generated_uuid = uuid.uuid4()\n",
    "\n",
    "# 将UUID转换为32位的int\n",
    "uuid_int = int(generated_uuid.int)\n",
    "\n",
    "print(\"生成的UUID：\", generated_uuid)\n",
    "print(\"转换为int型：\", uuid_int)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "paragraph_id = article_id = 33333"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "paragraph_vector = model.encode(\"你好世界，我想吃饭\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import Collection\n",
    "collection = Collection(name = \"article_paragraph_big\")      # Get an existing collection.\n",
    "data = [[paragraph_id], [article_id],[0],[paragraph_vector],[232]]\n",
    "mr = collection.insert(data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'article_paragraph_big'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "collection_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "collection2 = Collection(\n",
    "    name=\"article_paragraph\", \n",
    "    using='default', \n",
    "    shards_num=8,\n",
    "    consistency_level=\"Strong\"\n",
    "    )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "delete_expr = f\"paragraph_id == {33333}\"\n",
    "collection2.delete(delete_expr)\n",
    "\n",
    "# 可选: 执行压缩操作，清理标记为删除的数据\n",
    "collection2.compact()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "index_params = {\n",
    "  \"metric_type\":\"L2\",\n",
    "  \"index_type\":\"IVF_FLAT\",\n",
    "  \"params\":{\"nlist\":4096}\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Status(code=0, message=)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pymilvus import Collection, connections\n",
    "collection = Collection(collection_name)      # Get an existing collection.\n",
    "collection.create_index(\n",
    "  field_name=\"paragraph_vector\", \n",
    "  index_params=index_params\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import Collection\n",
    "collection = Collection(collection_name)      # Get an existing collection.\n",
    "collection.load()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import CollectionSchema, FieldSchema, DataType, Collection, connections\n",
    "\n",
    "\n",
    "class milvus_muster:\n",
    "    def __init__(self, host: str, port: str, alias: str, collection_name: str = \"article_paragraph\"):\n",
    "        connections.connect(\n",
    "            alias=alias,\n",
    "            host=host,\n",
    "            port=port\n",
    "        )\n",
    "\n",
    "        self.index_params = {\n",
    "            \"metric_type\": \"L2\",\n",
    "            \"index_type\": \"IVF_FLAT\",\n",
    "            \"params\": {\"nlist\": 1024}\n",
    "        }\n",
    "        self.collection_name = collection_name\n",
    "        self.collection = Collection(self.collection_name)  # Get an existing collection.\n",
    "        self.collection.create_index(\n",
    "            field_name=\"paragraph_vector\",\n",
    "            index_params=self.index_params\n",
    "        )\n",
    "\n",
    "        self.collection.load()\n",
    "        self.search_params = {\"metric_type\": \"L2\", \"params\": {\"nprobe\": 10}}\n",
    "\n",
    "    async def insert_vector(self, paragraph_id: str, article_id: str, paragraph_vector: list) -> None:\n",
    "        '''数据插入'''\n",
    "        paragraph_id = int(paragraph_id)\n",
    "        article_id = int(article_id)\n",
    "\n",
    "        collection = Collection(self.collection_name)  # Get an existing collection.\n",
    "        data = [[paragraph_id], [article_id], [0], [paragraph_vector]]\n",
    "        self.collection.insert(data)\n",
    "\n",
    "    async def get_top_paragraphs(self, Q_vector: list, articles: list) -> list:\n",
    "        '''通过问题与文章列表，检索相关段落(超过2篇文章)'''\n",
    "        ids = []\n",
    "        article_id_str = \"\"\n",
    "        for line in articles:\n",
    "            article_id_str += \" article_id == \" + str(line)\n",
    "        results = self.collection.search(\n",
    "            data=[list(Q_vector)],\n",
    "            anns_field=\"paragraph_vector\",\n",
    "            param=self.search_params,\n",
    "            limit=10,\n",
    "            expr=\"article_id == \" + str(line),\n",
    "            consistency_level=\"Strong\"\n",
    "        )\n",
    "        for line in results[0].ids:\n",
    "            ids.append(str(line))\n",
    "        return ids[:10]\n",
    "\n",
    "    async def get_comparison_paragraphs(self, Q_vector: list, articles: list) -> list:\n",
    "        '''通过问题与文章列表，检索相关段落(2篇文章)'''\n",
    "        ids = []\n",
    "        for line in articles:\n",
    "            results = self.collection.search(\n",
    "                data=[list(Q_vector)],\n",
    "                anns_field=\"paragraph_vector\",\n",
    "                param=self.search_params,\n",
    "                limit=10,\n",
    "                expr=\"article_id == \" + str(line),\n",
    "                consistency_level=\"Strong\"\n",
    "            )\n",
    "            ids.append(str(results[0].ids[0]))\n",
    "        return ids\n",
    "\n",
    "    def build(self) -> None:\n",
    "        '''构建集合'''\n",
    "        self.paragraph_id = FieldSchema(\n",
    "            name=\"paragraph_id\",\n",
    "            dtype=DataType.INT64,\n",
    "            is_primary=True\n",
    "        )\n",
    "\n",
    "        self.article_id = FieldSchema(\n",
    "            name=\"article_id\",\n",
    "            dtype=DataType.INT64\n",
    "        )\n",
    "\n",
    "        self.word_count = FieldSchema(\n",
    "            name=\"word_count\",\n",
    "            dtype=DataType.INT64\n",
    "        )\n",
    "        self.paragraph_vector = FieldSchema(\n",
    "            name=\"paragraph_vector\",\n",
    "            dtype=DataType.FLOAT_VECTOR,\n",
    "            dim=384\n",
    "        )\n",
    "        self.schema = CollectionSchema(\n",
    "            fields=[paragraph_id, article_id, word_count, paragraph_vector],\n",
    "            description=\"Paragraph search\"\n",
    "        )\n",
    "\n",
    "        self.collection = Collection(\n",
    "            name=self.collection_name,\n",
    "            schema=schema,\n",
    "            using='default',\n",
    "            shards_num=2,\n",
    "            consistency_level=\"Strong\"\n",
    "        )\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sentence_transformers import SentenceTransformer\n",
    "class Embedding:\n",
    "    def __init__(self):\n",
    "\n",
    "        self.model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')\n",
    "    def get_embedding(self, text: str) -> list:\n",
    "        '''文本转词向量'''\n",
    "        embeddings = self.model.encode(text)\n",
    "        return list(embeddings)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "ename": "FieldTypeException",
     "evalue": "<FieldTypeException: (code=0, message=The field of schema type must be FieldSchema.)>",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mFieldTypeException\u001b[0m                        Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-47-0a5e88802835>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m schema = CollectionSchema(\n\u001b[0m\u001b[1;32m      2\u001b[0m             \u001b[0mfields\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mparagraph_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0marticle_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mword_count\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparagraph_vector\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m             \u001b[0mdescription\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Paragraph_search\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m         )\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/orm/schema.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, fields, description, **kwargs)\u001b[0m\n\u001b[1;32m     37\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0mfield\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fields\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     38\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfield\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mFieldSchema\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 39\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0mFieldTypeException\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mExceptionsMessage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFieldType\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     40\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mprimary_field\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mfield\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     41\u001b[0m                 \u001b[0mfield\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_primary\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mFieldTypeException\u001b[0m: <FieldTypeException: (code=0, message=The field of schema type must be FieldSchema.)>"
     ]
    }
   ],
   "source": [
    "schema = CollectionSchema(\n",
    "            fields=[paragraph_id, article_id, word_count, paragraph_vector],\n",
    "            description=\"Paragraph_search\"\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "collection = Collection(\n",
    "            name=\"article_paragraph\",\n",
    "            schema=schema,\n",
    "            using='default',\n",
    "            shards_num=2,\n",
    "            consistency_level=\"Strong\"\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "search_params = {\"metric_type\": \"L2\", \"params\": {\"nprobe\": 10}}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[233524750408441189, 153546008563420080, 319681904401367092, 378752417796722145, 187528077588675447, 318345866768612330, 424144749677654774, 287193598808729433, 210437413246367943, 122571806592883084]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# collection.load()\n",
    "results = collection.search(\n",
    "    data=[list(model.encode(\"你好\"))], \n",
    "    anns_field=\"paragraph_vector\", \n",
    "    param=search_params, \n",
    "    limit=10, \n",
    "    expr=\"article_id == 100000\",\n",
    "    consistency_level=\"Strong\"\n",
    ")\n",
    "results[0].ids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pymilvus.orm.search.SearchResult at 0x7fe17f4b97f0>"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.on_result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "[\"\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Unexcepted error: [search], Field book_intro doesn't exist in schema, <Time: {'RPC start': '2023-10-12 11:59:26.755714', 'Exception': '2023-10-12 11:59:26.760200'}>\n"
     ]
    },
    {
     "ename": "ParamError",
     "evalue": "Field book_intro doesn't exist in schema",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mParamError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-30-0e6555894f48>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      6\u001b[0m   \u001b[0;34m\"expr\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"word_count <= 11000\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      7\u001b[0m }\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcollection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0msearch_param\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/orm/collection.py\u001b[0m in \u001b[0;36msearch\u001b[0;34m(self, data, anns_field, param, limit, expr, partition_names, output_fields, timeout, round_decimal, **kwargs)\u001b[0m\n\u001b[1;32m    688\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    689\u001b[0m         \u001b[0mconn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_connection\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 690\u001b[0;31m         res = conn.search(self._name, data, anns_field, param, limit, expr,\n\u001b[0m\u001b[1;32m    691\u001b[0m                           partition_names, output_fields, timeout, round_decimal, **kwargs)\n\u001b[1;32m    692\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"_async\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/decorators.py\u001b[0m in \u001b[0;36mhandler\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m     54\u001b[0m                     \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     55\u001b[0m                 \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 56\u001b[0;31m                     \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     57\u001b[0m                 \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     58\u001b[0m                     \u001b[0mcounter\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/decorators.py\u001b[0m in \u001b[0;36mhandler\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m     39\u001b[0m             \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     40\u001b[0m                 \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 41\u001b[0;31m                     \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     42\u001b[0m                 \u001b[0;32mexcept\u001b[0m \u001b[0mgrpc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRpcError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     43\u001b[0m                     \u001b[0;31m# DEADLINE_EXCEEDED means that the task wat not completed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/decorators.py\u001b[0m in \u001b[0;36mhandler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     84\u001b[0m             \u001b[0mrecord_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"Exception\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     85\u001b[0m             \u001b[0mLOGGER\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merror\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Unexcepted error: [{func.__name__}], {e}, <Time: {record_dict}>\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 86\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     87\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mhandler\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/decorators.py\u001b[0m in \u001b[0;36mhandler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     68\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     69\u001b[0m             \u001b[0mrecord_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"RPC start\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 70\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     71\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mBaseException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     72\u001b[0m             \u001b[0mrecord_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"RPC error\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/decorators.py\u001b[0m in \u001b[0;36mhandler\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m     19\u001b[0m             raise CollectionNotExistException(ErrorCode.CollectionNotExists,\n\u001b[1;32m     20\u001b[0m                                               f\"collection {collection_name} doesn't exist!\")\n\u001b[0;32m---> 21\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     22\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mhandler\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     23\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/client/grpc_handler.py\u001b[0m in \u001b[0;36msearch\u001b[0;34m(self, collection_name, data, anns_field, param, limit, expression, partition_names, output_fields, timeout, round_decimal, **kwargs)\u001b[0m\n\u001b[1;32m    449\u001b[0m         \u001b[0mts_utils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstruct_guarantee_ts\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconsistency_level\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcollection_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_kwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    450\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 451\u001b[0;31m         requests = Prepare.search_requests_with_expr(collection_name, data, anns_field, param, limit, expression,\n\u001b[0m\u001b[1;32m    452\u001b[0m                                                      partition_names, output_fields, round_decimal, **_kwargs)\n\u001b[1;32m    453\u001b[0m         \u001b[0m_kwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"schema\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/.local/lib/python3.8/site-packages/pymilvus/client/prepare.py\u001b[0m in \u001b[0;36msearch_requests_with_expr\u001b[0;34m(cls, collection_name, data, anns_field, param, limit, expr, partition_names, output_fields, round_decimal, **kwargs)\u001b[0m\n\u001b[1;32m    619\u001b[0m         \u001b[0mtag\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"$0\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    620\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0manns_field\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfields_name_locs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 621\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mParamError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Field {anns_field} doesn't exist in schema\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    622\u001b[0m         \u001b[0mdimension\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfields_schema\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfields_name_locs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0manns_field\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"params\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"dim\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    623\u001b[0m         \u001b[0mpls\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_prepare_placeholders\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnq\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_nq_per_batch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtag\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpl_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mis_binary\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdimension\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mParamError\u001b[0m: Field book_intro doesn't exist in schema"
     ]
    }
   ],
   "source": [
    "search_param = {\n",
    "  \"data\": [[0.1, 0.2]],\n",
    "  \"anns_field\": \"book_intro\",\n",
    "  \"param\": {\"metric_type\": \"L2\", \"params\": {\"nprobe\": 10}},\n",
    "  \"limit\": 2,\n",
    "  \"expr\": \"word_count <= 11000\",\n",
    "}\n",
    "res = collection.search(**search_param)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Milvus\n",
    "class Milvus:\n",
    "    HOST = 'localhost'\n",
    "    PORT = '19530'\n",
    "    ALIAS = 'default'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'localhost'"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Milvus.HOST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "def concatenate_content(your_list):  \n",
    "    result = ''  \n",
    "    for item in your_list:  \n",
    "        if item.get('role') == 'user':  \n",
    "            result += item.get('content', '')  \n",
    "    return result  \n",
    "  \n",
    "# 使用示例  \n",
    "your_list = [  \n",
    "    {'role': 'user', 'content': 'Hello, '},  \n",
    "    {'role': 'bot', 'content': 'Hi, how can I help you?'},  \n",
    "    {'role': 'user', 'content': 'Can you help me with Python?'}  \n",
    "]  \n",
    "  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello, Can you help me with Python?'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "concatenate_content(your_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
